<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/list.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="/js/jquery.min.js"></script>
    <script src="/js/tool.js"></script>
    <style>
        
        .nav{
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 50px;
        }
        .container{
            padding-top: 80px;
            height: auto;
        }
        .container-right{
            width: auto;
        }
        .blog-pagnation-wrapper{
            height: 40px;
            margin: 16px 0;
            text-align: center;
        }
        .blog-pagnation-item{
            display: inline-block;
            padding: 8px;
            border: 1px solid #d0d0d5;
            color: #333;
        }
        .blog-pagnation-item:hover{
            background: #4e4eeb;
            color: #fff;
        }
        .blog-pagnation-item.actvie{
            background: #4e4eeb;
            color: #fff;
        }

    </style>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="image/happy.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="login.html">登陆</a>
        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 右侧内容详情 -->
        <div class="container-right" style="width: 100%">
            <!-- 每一篇博客包含标题, 摘要, 时间 -->
            <div class="blog">

            </div>
            
            <hr>

        </div>
    </div>
</body>

<script>
    var descLength = 80; // 简介最大长度
    // 字符串截取，将文章正文截取成简介
    function mySubstr(content){
        if(content.length>descLength){
            return content.substr(0,descLength);
        }
        return content;
    }

    function getDraft(){
        $.ajax({
            url:"/art/getAll",
            method:"POST",
            data:{},
            success:function (result) {
                if (result.code == 200 && result.data != null) {
                        console.log(result.data);
                        //开始拼接
                        let content = result.data;
                        console.log(content);
                        let container = document.querySelector('.container-right');

                        for (let blog of content) {
                            if(blog.state==0){
                                var tnum
                                let blogDiv = document.createElement('div');
                                blogDiv.className = 'blog';
                                // 创建博客标题
                                let titleDiv = document.createElement('div');
                                titleDiv.className = 'title';
                                titleDiv.innerHTML = blog.title + "（草稿）";
                                blogDiv.appendChild(titleDiv);
                                // 创建日期
                                let dateDiv = document.createElement('div');//外层
                                dateDiv.className = 'date';
                                //点赞数
                                let thumbSpan = document.createElement('span');
                                thumbSpan.className = 'thumbNum';
                                thumbSpan.innerHTML = "点赞数：" + blog.thumb + " ";
                                //创建时间
                                let dateSpan = document.createElement('span');
                                dateSpan.className = 'data';
                                dateSpan.innerHTML = blog.createtime;
                                //阅读量
                                let rcountSpan = document.createElement('span');
                                rcountSpan.className = 'rcount';
                                rcountSpan.innerHTML = "阅读量:" + blog.rcount + " ";

                                //拼接
                                dateDiv.appendChild(dateSpan);
                                dateDiv.appendChild(thumbSpan);
                                dateDiv.appendChild(rcountSpan);
                                blogDiv.appendChild(dateDiv);
                                // 创建摘要
                                let descDiv = document.createElement('div');
                                descDiv.className = 'desc';
                                descDiv.innerHTML = mySubstr(blog.content);
                                blogDiv.appendChild(descDiv);
                                // 创建查看全文按钮
                                let a = document.createElement('a');
                                a.innerHTML="继续编辑>>"
                                a.href = 'blog_update.html?id=' + blog.id;

                                blogDiv.appendChild(a);


                                // 把 blogDiv 加入外层元素
                                container.appendChild(blogDiv);
                            }

                        }


                } else {
                    alert("<h1>暂无数据</h1>");
                }
            }
        })
    }
    getDraft();
</script>
</html>